/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.rcs.database;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import org.rcs.folders.ItemsFactory;
import org.rcs.folders.VirtualItem;
import org.rcs.servlets.utils.XMLConfig;

/**
 *
 * @author ruben
 */
public class DatabaseItemsFactory implements ItemsFactory {

  private DatabaseItemsFactoryConfig config ; 
  
  private static final VirtualItem[] EMPTY_SYSTEM = new VirtualItem[0];
  
  private PersistenceManager pm ;
  
  @Override
  public void init() {
    PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("MediaDatabase");
    pm = pmf.getPersistenceManager();
  }

  @Override
  public void destroy() {
    if (null != pm)
      pm.close();
  }

  @Override
  public String getName() {
    return getConfig().getName() ;
  }

  @Override
  public boolean isEnabled() {
    return getConfig().isEnabled() ;
  }

  @Override
  public VirtualItem[] getVideoItemsRoot() {
    return EMPTY_SYSTEM ;
  }

  @Override
  public VirtualItem[] getAudioItemsRoot() {
    return EMPTY_SYSTEM ;
  }

  @Override
  public VirtualItem[] getPictureItemsRoot() {
    return EMPTY_SYSTEM ;
  }
  
  private DatabaseItemsFactoryConfig getConfig() {
    config = XMLConfig.get(config, DatabaseItemsFactoryConfig.class) ;

    return config;
  }  
}
